package com.athena.api.model.messaging;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import com.athena.dal.entities.User;

public class Conversation {
	
	private User user;
	private List<Message> messages;

	public Conversation(User user) {
		this.user = user;
		messages = new ArrayList<Message>();
	}

	public User getUser() {
		return user;
	}


	public boolean add(Message message) {
		return messages.add(message);
	}
	
	public Message[] getMessages() {
		Collections.sort(messages, new Comparator<Message>() {

			@Override
			public int compare(Message mesg1, Message mesg2) {
				return mesg1.getTime().compareTo(mesg2.getTime());
			}
		});
		return messages.toArray(new Message[messages.size()]);//messages;
	}
	
}
